function axios(params) {
	let {
		method,
		url,
		data,
		token,
		isLoading,
		tipsTime
	} = params;
	token = token || '';
	method = method || 'POST';
	tipsTime = tipsTime?parseInt(tipsTime) : 3000 
	data = data || {};
	let Token =  getApp().globalData.Token ;
	if(data.LoginUserType != 1){
		data.userId = getApp().globalData.UserId
		data.Account = getApp().globalData.Account
		data.account = getApp().globalData.Account
		// data.ModuleID = getApp().globalData.ModuleID
	}
	if (!url) return uni.showToast({
		title: '请求地址无效，请确认',
		icon: 'none'
	});
	if(isLoading){
		uni.showLoading({
			title:'加载中...',
			mask:true
		})
	}
	if(url.indexOf('https://') == -1 && url.indexOf('http://') == -1){
		url = getApp().globalData.BaseURL + url
	}
	let DDD =  JSON.parse(JSON.stringify(data))
	let savedata = fileterQuery(DDD)
	let SSS = {url : url,data: savedata }
	// console.log(JSON.stringify(SSS));
	// console.log(url);
	// console.log(Token);
	// console.log(666,savedata);
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: method,
			data: savedata ,
			header: { Authorization:'BasicAuth '+Token },
			success: (res) => {
				// 延时取消加载中动画
				// console.log('走进封装的axios='+url+JSON.stringify(res));
				uni.hideLoading()
				if (res.statusCode == 401) {
					uni.showToast({
						title: '权限已失效，请重新登录。',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}, 1500)
					return ;
				} else if (res.statusCode == 405) {
					uni.showToast({
						title: '请求失败：状态码' + res.statusCode + '->错误原因=' + res.data.Message,
						icon: 'none',
						duration: 3000
					})
					return reject(405);
				} else if (res.statusCode != 200) {
					uni.showToast({
						title: '请求失败：状态码=' + res.statusCode + '->错误原因=' + res.data.Message,
						icon: 'none',
						duration: 3000
					})
					return reject(res.statusCode);
				}else if (!res.data.IsSuccess) {
					console.log(444,res.data);
					if(!res.data.MessageType || res.data.MessageType == 'tip'){
						if(res.data.Message.length > 30){
							uni.showModal({
								title: '提示',
								content: res.data.Message ,
								showCancel: false ,
								confirmText: '我知道了',
								success(res) {}
							})
						}else{
							uni.showToast({
								title: '请求失败：' + res.data.Message,
								icon: 'none',
								duration: tipsTime
							})
						}
					}
					reject(res.data);
					return;
				}
				if(!res.data.Message) res.data.Message = '';
				return resolve(res.data);
			},
			fail: (err) => {
				console.log(err);
				uni.hideLoading()
				uni.showToast({
					title: '网络服务异常：' + err.errMsg,
					icon: 'none'
				})
			}
		})
	})
}

function fileterQuery(data){
	for(let i in data){
		if(i.indexOf('Index')>-1 || i.indexOf('Range')>-1 ||  i.indexOf('isShowTimeCtr')>-1  ){
			delete data[i]
		}
	}
	return data ;
}

module.exports = {
	axios
}
